<?php
$isReloadable = true;
$isPopUp = true;
require_once("../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');

if (reqVar('azione')=='conferma') {
	$sListaAgende = "";
	foreach($_REQUEST as $nX => $vX) {
		if (substr($nX,0,7)!='cb_idut') continue;
		$sListaAgende .= substr($nX,7).",";
	}
	if ($sListaAgende == "") {
		$msgPag .= _t("seleziona almeno un'agenda");
	} else {
		$sListaAgende = substr($sListaAgende,0,-1);
		echo "chiusura in corso ...";	
		echo "<script>\n";
		echo "window.opener.location.href='agenView.php?listAge=$sListaAgende&$sXSNQS';\n";
		echo "window.close();\n";
		echo "</script>\n";
		exit();
	}
}
$sListaAgende = $objSess->getSV('agenda','listAge');
if ($sListaAgende=='') {
	$sListaAgende = $objSess->aSV['agenda']['listaAge'] = $objSess->idUtente;
}
$aAgende = explode(",",$sListaAgende);
foreach($aAgende as $idX) {
	reqDef('cb_idut'.$idX,'S');
}
$sSql = "SELECT * FROM ovf_utenti ORDER BY cognome,nome";
$objDB->query($sSql,'selUte');


$sCmdL  = "";

$sCmdR  = "&nbsp;&nbsp;&nbsp";
$sCmdR .=  "<a class='cmd1' href=\"javascript:document.frm1.azione.value='conferma';document.frm1.submit();\">"._t("conferma")."</a>";
$sCmdR .= "&nbsp;&nbsp;&nbsp";
$sCmdR .=  "<a class='cmd1' href='javascript:window.close();'>"._t("chiudi")."</a>";
$aOpt = array("width"=>600);
echo getTestaPopUpHtml("Selezione agende",$msgPag, $aOpt);
?>
<script type="text/javascript">
function confAgg() {
   if (confirm("<?=_t("Confermi l'aggiornamento della struttura del data-base ?")?>")) {
      document.frm1.azione.value='aggiorna';
      document.frm1.submit();
   }
}
function setAllCb() {
   oSetAllCbx = document.getElementById("set_all_cb");
   if (!oSetAllCbx) {
      alert("set_all_cb ?");
      return;
   }
   for(k=0; k<document.frm1.elements.length; k++) {
      oElem = document.frm1.elements[k];
      if (oElem.name.substring(0,7)!=('cb_idut')) continue;
      oElem.checked = oSetAllCbx.checked;
   }
}
</script>
<?
echo getHtmlForm();
echo getHtmlHidden('xsn');
echo getHtmlHidden('azione','...');
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<tr>
		<td class="lab1" width='1%'>
		   <?
		   echo getHtmlCheckBox('set_all_cb', 'S','@REQ',array('onClick'=>"setAllCb();"));
		   ?>
		</td>
		<td class="lab1" width='99%'><?=_t("Agenda")?></td>
	</tr>
<?php 
$sTxtX = 'txt1';
while($acUte = $objDB->fetch('selUte')) {
	$sTxtX = ($sTxtX=='txt1')?'txt2':'txt1';
?>
	<tr>
		<td class="<?php echo $sTxtX?>" >
			<? echo getHtmlCheckBox('cb_idut'.$acUte['id_utente'], 'S');?>
		</td>
		<td class="<?php echo $sTxtX?>" >
			<? echo $acUte['cognome']." ".$acUte['nome'];?>
		</td>
	</tr>
<?php 
}
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<?php 
//print_r($aArt);
echo "</form>\n";
echo getCodaPopUpHtml();